package com.eCommerce.server.corebackend.sisv;

import java.util.Map;



public class SISVFinder {
	public SISVFinder()
	  {
		  
	  }
	  
	  /**
	   * Dictionary where we store the SISV Components of a project.
	   * Any SISV Component will be store with a key. 
	   * 
	   */
		private Map<String,ISimpleService> map;	

		/**
		 * Assign a map to the SISVFinder
		 * throws an exception if the map has already been set
		 * @param value
		 * @throws Exception
		 */
		public void setMap(Map<String,ISimpleService> value) throws Exception
		{

			// If map is already loaded, throw exception
			if (map != null)
	      {
	          String msg = "The dictionary of SISV components are already load. You can not do it again...";
	          Exception ex = new Exception(msg);
	          throw ex;
	      }

	      map = value;
		}
		
		
		
		/**
		 * Get a simple service though its key
		 */
		public ISimpleService get(String key) throws Exception 
		{
			
			try
	      {
	          // To do make sure that the caller is an ISVCO

	          ISimpleService sisv = (ISimpleService)map.get(key);
	          if (sisv == null)
	              throw new Exception("The key -" + key + "- are not defined in SISV Finder");
	          return sisv;
	      }
	      catch (Exception ex)
	      {
	          String exMsg = ex.getMessage();
	          if (map == null)exMsg = "The Dictionry of SISV Component are empty";

	          String msg = "Error while getting SISV component : " + key + ". DETAILS:" + exMsg;
	          throw new Exception(msg);
	      }
		}

}
